/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package twitterSearch;

import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.TermFreqVector;
import org.apache.lucene.store.Directory;

/**
 *
 * @author Livia
 */
public class TwitterLuceneSearch {
    
    private Directory directory;
    private int numDocs;
    private IndexReader reader;
    TermFreqVector[] vectors;
    
    public TwitterLuceneSearch(Directory dir) throws IOException{
        this.directory = dir;
        reader = IndexReader.open(directory);
        numDocs = reader.maxDoc();
        
    }
    
    public TermFreqVector[] makeVectors() throws IOException{
        vectors = new TermFreqVector[numDocs];
        for (int i = 0; i < numDocs; i++){
            vectors[i] = null;
            vectors[i] = reader.getTermFreqVector(i, "content");  
        }
        return vectors;
    }
    
    public void printVectors() throws IOException{
        System.out.println("\n------- VECTORS DOS TWEETS-------\n");
        for (int i = 0; i < numDocs; i++){
            System.out.print("\n---DOC "+i+"---\n");
            if(vectors[i] != null){
                for (int j = 0; j < vectors[i].size(); j++)  //## aqui da erro nullpointerex pq?????
                    System.out.println("Term: "+vectors[i].getTerms()[j] +
                            " Frequency: "+vectors[i].getTermFrequencies()[j]);
            }
        }        
    }
    
    public int getNumVectors(){
        return numDocs;
    }
    

}
